package com.cucheng.chatroom.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cucheng.chatroom.dao.GroupInfoDao;
import com.cucheng.chatroom.dao.UserInfoDao;
import com.cucheng.chatroom.model.po.GroupInfo;
import com.cucheng.chatroom.model.po.UserInfo;
import com.cucheng.chatroom.service.UserInfoService;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    private static final Logger LOGGER = LoggerFactory.getLogger (UserInfoServiceImpl.class);
    @Autowired
    private UserInfoDao  userInfoDao;
    @Autowired
    private GroupInfoDao groupInfoDao;

    /**
     *@Description: TODO(根据用户昵称登录) 
     *@Author: wangchengjie
     *@Since: 2019年3月30日上午9:39:47
     *@param username
     *@return
     */
    @Override
    public UserInfo getByUsername(String username){
        return userInfoDao.selectByUsername (username);
    }

    /**
     *@Description: TODO(登录用户获取用户好友，群组信息) 
     *@Author: wangchengjie
     *@Since: 2019年3月30日下午3:36:58
     *@param uinfo
     *@return
     */
    @Override
    public UserInfo getUserInfoList(UserInfo uinfo){
        try {
            List<UserInfo> uList = userInfoDao.selectUserByFrendId (uinfo);
            List<GroupInfo> groupList = groupInfoDao.selectGroupByUserId (uinfo.getUserId ());
            uinfo.setFriendList (uList);
            uinfo.setGroupList (groupList);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error (e.getMessage ());
        }
        return uinfo;
    }

}
